home *** CD-ROM | disk | FTP | other *** search
/ Mac Easy 2010 May / Mac Life Ubuntu.iso / casper / filesystem.squashfs / var / lib / dpkg / info / xcursor-themes.prerm < prev    next >
Encoding:
Text File  |  2006-11-16  |  30.3 KB  |  937 lines

  1. #!/bin/sh
  2. # Debian xcursor-themes package pre-removal script
  3. # Copyright 2003 Daniel Stone, Branden Robinson.
  4. # Copyright 2004 Branden Robinson.
  5. # Licensed under the GNU General Public License, version 2.  See the file
  6. # /usr/share/common-licenses/GPL or <http://www.gnu.org/copyleft/gpl.txt>.
  7. # Acknowledgements to Stephen Early, Mark Eichin, and Manoj Srivastava.
  8.  
  9. # $Id: xcursor-themes.prerm.in 1860 2006-04-19 01:27:05Z vorlon $
  10.  
  11. set -e
  12.  
  13. THIS_PACKAGE=xcursor-themes
  14. THIS_SCRIPT=prerm
  15.  
  16. # $Id: xsfbs.sh 2888 2006-08-22 03:04:13Z dnusinow $
  17.  
  18. # This is the X Strike Force shell library for X Window System package
  19. # maintainer scripts.  It serves to define shell functions commonly used by
  20. # such packages, and performs some error checking necessary for proper operation
  21. # of those functions.  By itself, it does not "do" much; the maintainer scripts
  22. # invoke the functions defined here to accomplish package installation and
  23. # removal tasks.
  24.  
  25. # If you are reading this within a Debian package maintainer script (e.g.,
  26. # /var/lib/dpkg)info/PACKAGE.{config,preinst,postinst,prerm,postrm}), you can
  27. # skip past this library by scanning forward in this file to the string
  28. # "GOBSTOPPER".
  29.  
  30. SOURCE_VERSION=1.0.1-5ubuntu1
  31. OFFICIAL_BUILD=
  32.  
  33. # Use special abnormal exit codes so that problems with this library are more
  34. # easily tracked down.
  35. SHELL_LIB_INTERNAL_ERROR=86
  36. SHELL_LIB_THROWN_ERROR=74
  37. SHELL_LIB_USAGE_ERROR=99
  38.  
  39. # old -> new variable names
  40. if [ -z "$DEBUG_XORG_PACKAGE" ] && [ -n "$DEBUG_XFREE86_PACKAGE" ]; then
  41.   DEBUG_XORG_PACKAGE="$DEBUG_XFREE86_PACKAGE"
  42. fi
  43. if [ -z "$DEBUG_XORG_DEBCONF" ] && [ -n "$DEBUG_XFREE86_DEBCONF" ]; then
  44.   DEBUG_XORG_DEBCONF="$DEBUG_XFREE86_DEBCONF"
  45. fi
  46.  
  47. # initial sanity checks
  48. if [ -z "$THIS_PACKAGE" ]; then
  49.   cat >&2 <<EOF
  50. Error: package maintainer script attempted to use shell library without
  51. definining \$THIS_PACKAGE shell variable.  Please report the package name,
  52. version, and the text of this error message to the Debian Bug Tracking System.
  53. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  54. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  55. "doc-debian" package, or install the "reportbug" package and use the command of
  56. the same name to file a report against version $SOURCE_VERSION of this package.
  57. EOF
  58.   exit $SHELL_LIB_USAGE_ERROR
  59. fi
  60.  
  61. if [ -z "$THIS_SCRIPT" ]; then
  62.   cat >&2 <<EOF
  63. Error: package maintainer script attempted to use shell library without
  64. definining \$THIS_SCRIPT shell variable.  Please report the package name,
  65. version, and the text of this error message to the Debian Bug Tracking System.
  66. Visit <http://www.debian.org/Bugs/Reporting> on the World Wide Web for
  67. instructions, read the file /usr/share/doc/debian/bug-reporting.txt from the
  68. "doc-debian" package, or install the "reportbug" package and use the command of
  69. the same name to file a report against version $SOURCE_VERSION of the
  70. "$THIS_PACKAGE" package.
  71. EOF
  72.   exit $SHELL_LIB_USAGE_ERROR
  73. fi
  74.  
  75. ARCHITECTURE="$(dpkg --print-installation-architecture)"
  76.  
  77. LAPTOP=""
  78. if [ -n "$(which laptop-detect)" ]; then
  79.     if laptop-detect >/dev/null; then
  80.     LAPTOP=true
  81.     fi
  82. fi
  83.  
  84. if [ "$1" = "reconfigure" ] || [ -n "$DEBCONF_RECONFIGURE" ]; then
  85.   RECONFIGURE="true"
  86. else
  87.   RECONFIGURE=
  88. fi
  89.  
  90. if ([ "$1" = "install" ] || [ "$1" = "configure" ]) && [ -z "$2" ]; then
  91.   FIRSTINST="yes"
  92. fi
  93.  
  94. if [ -z "$RECONFIGURE" ] && [ -z "$FIRSTINST" ]; then
  95.   UPGRADE="yes"
  96. fi
  97.  
  98. trap "message;\
  99.       message \"Received signal.  Aborting $THIS_PACKAGE package $THIS_SCRIPT script.\";\
  100.       message;\
  101.       exit 1" HUP INT QUIT TERM
  102.  
  103. reject_nondigits () {
  104.   # syntax: reject_nondigits [ operand ... ]
  105.   #
  106.   # scan operands (typically shell variables whose values cannot be trusted) for
  107.   # characters other than decimal digits and barf if any are found
  108.   while [ -n "$1" ]; do
  109.     # does the operand contain anything but digits?
  110.     if ! expr "$1" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  111.       # can't use die(), because it wraps message() which wraps this function
  112.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_nondigits() encountered" \
  113.            "possibly malicious garbage \"$1\"" >&2
  114.       exit $SHELL_LIB_THROWN_ERROR
  115.     fi
  116.     shift
  117.   done
  118. }
  119.  
  120. reject_whitespace () {
  121.   # syntax: reject_whitespace [ operand ]
  122.   #
  123.   # scan operand (typically a shell variable whose value cannot be trusted) for
  124.   # whitespace characters and barf if any are found
  125.   if [ -n "$1" ]; then
  126.     # does the operand contain any whitespace?
  127.     if expr "$1" : "[[:space:]]" > /dev/null 2>&1; then
  128.       # can't use die(), because I want to avoid forward references
  129.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_whitespace() encountered" \
  130.            "possibly malicious garbage \"$1\"" >&2
  131.       exit $SHELL_LIB_THROWN_ERROR
  132.     fi
  133.   fi
  134. }
  135.  
  136. reject_unlikely_path_chars () {
  137.   # syntax: reject_unlikely_path_chars [ operand ... ]
  138.   #
  139.   # scan operands (typically shell variables whose values cannot be trusted) for
  140.   # characters unlikely to be seen in a path and which the shell might
  141.   # interpret and barf if any are found
  142.   while [ -n "$1" ]; do
  143.     # does the operand contain any funny characters?
  144.     if expr "$1" : '.*[!$&()*;<>?|].*' > /dev/null 2>&1; then
  145.       # can't use die(), because I want to avoid forward references
  146.       echo "$THIS_PACKAGE $THIS_SCRIPT error: reject_unlikely_path_chars()" \
  147.            "encountered possibly malicious garbage \"$1\"" >&2
  148.       exit $SHELL_LIB_THROWN_ERROR
  149.     fi
  150.     shift
  151.   done
  152. }
  153.  
  154. # Query the terminal to establish a default number of columns to use for
  155. # displaying messages to the user.  This is used only as a fallback in the
  156. # event the COLUMNS variable is not set.  ($COLUMNS can react to SIGWINCH while
  157. # the script is running, and this cannot, only being calculated once.)
  158. DEFCOLUMNS=$(stty size 2> /dev/null | awk '{print $2}') || true
  159. if ! expr "$DEFCOLUMNS" : "[[:digit:]]\+$" > /dev/null 2>&1; then
  160.   DEFCOLUMNS=80
  161. fi
  162.  
  163. message () {
  164.   # pretty-print messages of arbitrary length
  165.   reject_nondigits "$COLUMNS"
  166.   echo "$*" | fmt -t -w ${COLUMNS:-$DEFCOLUMNS} >&2
  167. }
  168.  
  169. observe () {
  170.   # syntax: observe message ...
  171.   #
  172.   # issue observational message suitable for logging someday when support for
  173.   # it exists in dpkg
  174.   if [ -n "$DEBUG_XORG_PACKAGE" ]; then
  175.     message "$THIS_PACKAGE $THIS_SCRIPT note: $*"
  176.   fi
  177. }
  178.  
  179. warn () {
  180.   # syntax: warn message ...
  181.   #
  182.   # issue warning message suitable for logging someday when support for
  183.   # it exists in dpkg; also send to standard error
  184.   message "$THIS_PACKAGE $THIS_SCRIPT warning: $*"
  185. }
  186.  
  187. die () {
  188.   # syntax: die message ...
  189.   #
  190.   # exit script with error message
  191.   message "$THIS_PACKAGE $THIS_SCRIPT error: $*"
  192.   exit $SHELL_LIB_THROWN_ERROR
  193. }
  194.  
  195. internal_error () {
  196.   # exit script with error; essentially a "THIS SHOULD NEVER HAPPEN" message
  197.   message "internal error: $*"
  198.   if [ -n "$OFFICIAL_BUILD" ]; then
  199.     message "Please report a bug in the $THIS_SCRIPT script of the" \
  200.             "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  201.             "Tracking System.  Include all messages above that mention the" \
  202.             "$THIS_PACKAGE package.  Visit " \
  203.             "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  204.             "instructions, read the file" \
  205.             "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  206.             "package, or install the reportbug package and use the command of" \
  207.             "the same name to file a report."
  208.   fi
  209.   exit $SHELL_LIB_INTERNAL_ERROR
  210. }
  211.  
  212. usage_error () {
  213.   message "usage error: $*"
  214.   message "Please report a bug in the $THIS_SCRIPT script of the" \
  215.           "$THIS_PACKAGE package, version $SOURCE_VERSION to the Debian Bug" \
  216.           "Tracking System.  Include all messages above that mention the" \
  217.           "$THIS_PACKAGE package.  Visit " \
  218.           "<http://www.debian.org/Bugs/Reporting> on the World Wide Web for" \
  219.           "instructions, read the file" \
  220.           "/usr/share/doc/debian/bug-reporting.txt from the doc-debian" \
  221.           "package, or install the reportbug package and use the command of" \
  222.           "the same name to file a report."
  223.   exit $SHELL_LIB_USAGE_ERROR
  224. }
  225.  
  226.  
  227. maplink () {
  228.   # returns what symlink should point to; i.e., what the "sane" answer is
  229.   # Keep this in sync with the debian/*.links files.
  230.   # This is only needed for symlinks to directories.
  231.   #
  232.   # XXX: Most of these look wrong in the X11R7 world and need to be fixed.
  233.   # If we've stopped using this function, fixing it might enable us to re-enable
  234.   # it again and catch more errors.
  235.   case "$1" in
  236.     /etc/X11/xkb/compiled) echo /var/lib/xkb ;;
  237.     /etc/X11/xkb/xkbcomp) echo /usr/X11R6/bin/xkbcomp ;;
  238.     /usr/X11R6/lib/X11/app-defaults) echo /etc/X11/app-defaults ;;
  239.     /usr/X11R6/lib/X11/fs) echo /etc/X11/fs ;;
  240.     /usr/X11R6/lib/X11/lbxproxy) echo /etc/X11/lbxproxy ;;
  241.     /usr/X11R6/lib/X11/proxymngr) echo /etc/X11/proxymngr ;;
  242.     /usr/X11R6/lib/X11/rstart) echo /etc/X11/rstart ;;
  243.     /usr/X11R6/lib/X11/twm) echo /etc/X11/twm ;;
  244.     /usr/X11R6/lib/X11/xdm) echo /etc/X11/xdm ;;
  245.     /usr/X11R6/lib/X11/xinit) echo /etc/X11/xinit ;;
  246.     /usr/X11R6/lib/X11/xkb) echo /etc/X11/xkb ;;
  247.     /usr/X11R6/lib/X11/xserver) echo /etc/X11/xserver ;;
  248.     /usr/X11R6/lib/X11/xsm) echo /etc/X11/xsm ;;
  249.     /usr/bin/X11) echo ../X11R6/bin ;;
  250.     /usr/bin/rstartd) echo ../X11R6/bin/rstartd ;;
  251.     /usr/include/X11) echo ../X11R6/include/X11 ;;
  252.     /usr/lib/X11) echo ../X11R6/lib/X11 ;;
  253.     *) internal_error "maplink() called with unknown path \"$1\"" ;;
  254.   esac
  255. }
  256.  
  257. analyze_path () {
  258.   # given a supplied set of pathnames, break each one up by directory and do an
  259.   # ls -dl on each component, cumulatively; i.e.
  260.   # analyze_path /usr/X11R6/bin -> ls -dl /usr /usr/X11R6 /usr/X11R6/bin
  261.   # Thanks to Randolph Chung for this clever hack.
  262.  
  263.   #local f g
  264.  
  265.   while [ -n "$1" ]; do
  266.     reject_whitespace "$1"
  267.     _g=
  268.     message "Analyzing $1:"
  269.     for _f in $(echo "$1" | tr / \  ); do
  270.       if [ -e /$_g$_f ]; then
  271.         ls -dl /$_g$_f /$_g$_f.dpkg-* 2> /dev/null || true
  272.         _g=$_g$_f/
  273.       else
  274.         message "/$_g$_f: nonexistent; directory contents of /$_g:"
  275.         ls -l /$_g
  276.         break
  277.       fi
  278.     done
  279.     shift
  280.   done
  281. }
  282.  
  283. find_culprits () {
  284.   #local f p dpkg_info_dir possible_culprits smoking_guns bad_packages package \
  285.   #  msg
  286.  
  287.   reject_whitespace "$1"
  288.   message "Searching for overlapping packages..."
  289.   _dpkg_info_dir=/var/lib/dpkg/info
  290.   if [ -d $_dpkg_info_dir ]; then
  291.     if [ "$(echo $_dpkg_info_dir/*.list)" != "$_dpkg_info_dir/*.list" ]; then
  292.       _possible_culprits=$(ls -1 $_dpkg_info_dir/*.list | egrep -v \
  293.         "(xbase-clients|x11-common|xfs|xlibs)")
  294.       if [ -n "$_possible_culprits" ]; then
  295.         _smoking_guns=$(grep -l "$1" $_possible_culprits || true)
  296.         if [ -n "$_smoking_guns" ]; then
  297.           _bad_packages=$(printf "\\n")
  298.           for f in $_smoking_guns; do
  299.             # too bad you can't nest parameter expansion voodoo
  300.             p=${f%*.list}      # strip off the trailing ".list"
  301.             _package=${p##*/}   # strip off the directories
  302.             _bad_packages=$(printf "%s\n%s" "$_bad_packages" "$_package")
  303.           done
  304.           _msg=$(cat <<EOF
  305. The following packages appear to have file overlaps with the X.Org packages;
  306. these packages are either very old, or in violation of Debian Policy.  Try
  307. upgrading each of these packages to the latest available version if possible:
  308. for example, with the command "apt-get install".  If no newer version of a
  309. package is available, you will have to remove it; for example, with the command
  310. "apt-get remove".  If even the latest available version of the package has
  311. this file overlap, please file a bug against that package with the Debian Bug
  312. Tracking System.  You may want to refer the package maintainer to section 12.8
  313. of the Debian Policy manual.
  314. EOF
  315. )
  316.           message "$_msg"
  317.           message "The overlapping packages are: $_bad_packages"
  318.         else
  319.           message "no overlaps found."
  320.         fi
  321.       fi
  322.     else
  323.       message "cannot search; no matches for $_dpkg_info_dir/*.list."
  324.     fi
  325.   else
  326.     message "cannot search; $_dpkg_info_dir does not exist."
  327.   fi
  328. }
  329.  
  330. # we require a readlink command or shell function
  331. if ! which readlink > /dev/null 2>&1; then
  332.   message "The readlink command was not found.  Please install version" \
  333.           "1.13.1 or later of the debianutils package."
  334.   readlink () {
  335.     # returns what symlink in $1 actually points to
  336.     perl -e '$l = shift; exit 1 unless -l $l; $r = readlink $l; exit 1 unless $r; print "$r\n"' "$1"
  337.   }
  338. fi
  339.  
  340. check_symlink () {
  341.   # syntax: check_symlink symlink
  342.   #
  343.   # See if specified symlink points where it is supposed to.  Return 0 if it
  344.   # does, and 1 if it does not.
  345.   #
  346.   # Primarily used by check_symlinks_and_warn() and check_symlinks_and_bomb().
  347.  
  348.   #local symlink
  349.  
  350.   # validate arguments
  351.   if [ $# -ne 1 ]; then
  352.     usage_error "check_symlink() called with wrong number of arguments;" \
  353.                 "expected 1, got $#"
  354.     exit $SHELL_LIB_USAGE_ERROR
  355.   fi
  356.  
  357.   _symlink="$1"
  358.  
  359.   if [ "$(maplink "$_symlink")" = "$(readlink "$_symlink")" ]; then
  360.     return 0
  361.   else
  362.     return 1
  363.   fi
  364. }
  365.  
  366. check_symlinks_and_warn () {
  367.   # syntax: check_symlinks_and_warn symlink ...
  368.   #
  369.   # For each argument, check for symlink sanity, and warn if it isn't sane.
  370.   #
  371.   # Call this function from a preinst script in the event $1 is "upgrade" or
  372.   # "install".
  373.  
  374.   #local errmsg symlink
  375.  
  376.   # validate arguments
  377.   if [ $# -lt 1 ]; then
  378.     usage_error "check_symlinks_and_warn() called with wrong number of" \
  379.                 "arguments; expected at least 1, got $#"
  380.     exit $SHELL_LIB_USAGE_ERROR
  381.   fi
  382.  
  383.   while [ -n "$1" ]; do
  384.     _symlink="$1"
  385.     if [ -L "$_symlink" ]; then
  386.       if ! check_symlink "$_symlink"; then
  387.         observe "$_symlink symbolic link points to wrong location" \
  388.                 "$(readlink "$_symlink"); removing"
  389.         rm "$_symlink"
  390.       fi
  391.     elif [ -e "$_symlink" ]; then
  392.       _errmsg="$_symlink exists and is not a symbolic link; this package cannot"
  393.       _errmsg="$_errmsg be installed until this"
  394.       if [ -f "$_symlink" ]; then
  395.         _errmsg="$_errmsg file"
  396.       elif [ -d "$_symlink" ]; then
  397.         _errmsg="$_errmsg directory"
  398.       else
  399.         _errmsg="$_errmsg thing"
  400.       fi
  401.       _errmsg="$_errmsg is removed"
  402.       die "$_errmsg"
  403.     fi
  404.     shift
  405.   done
  406. }
  407.  
  408. check_symlinks_and_bomb () {
  409.   # syntax: check_symlinks_and_bomb symlink ...
  410.   #
  411.   # For each argument, check for symlink sanity, and bomb if it isn't sane.
  412.   #
  413.   # Call this function from a postinst script.
  414.  
  415.   #local problem symlink
  416.  
  417.   # validate arguments
  418.   if [ $# -lt 1 ]; then
  419.     usage_error "check_symlinks_and_bomb() called with wrong number of"
  420.                 "arguments; expected at least 1, got $#"
  421.     exit $SHELL_LIB_USAGE_ERROR
  422.   fi
  423.  
  424.   while [ -n "$1" ]; do
  425.     _problem=
  426.     _symlink="$1"
  427.     if [ -L "$_symlink" ]; then
  428.       if ! check_symlink "$_symlink"; then
  429.         _problem=yes
  430.         warn "$_symlink symbolic link points to wrong location" \
  431.              "$(readlink "$_symlink")"
  432.       fi
  433.     elif [ -e "$_symlink" ]; then
  434.       _problem=yes
  435.       warn "$_symlink is not a symbolic link"
  436.     else
  437.       _problem=yes
  438.       warn "$_symlink symbolic link does not exist"
  439.     fi
  440.     if [ -n "$_problem" ]; then
  441.       analyze_path "$_symlink" "$(readlink "$_symlink")"
  442.       find_culprits "$_symlink"
  443.       die "bad symbolic links on system"
  444.     fi
  445.     shift
  446.   done
  447. }
  448.  
  449. font_update () {
  450.   # run $UPDATECMDS in $FONTDIRS
  451.  
  452.   #local dir cmd shortcmd x_font_dir_prefix
  453.  
  454.   _x_font_dir_prefix="/usr/share/fonts/X11"
  455.  
  456.   if [ -z "$UPDATECMDS" ]; then
  457.     usage_error "font_update() called but \$UPDATECMDS not set"
  458.   fi
  459.   if [ -z "$FONTDIRS" ]; then
  460.     usage_error "font_update() called but \$FONTDIRS not set"
  461.   fi
  462.  
  463.   reject_unlikely_path_chars "$UPDATECMDS"
  464.   reject_unlikely_path_chars "$FONTDIRS"
  465.  
  466.   for _dir in $FONTDIRS; do
  467.     if [ -d "$_x_font_dir_prefix/$_dir" ]; then
  468.       for _cmd in $UPDATECMDS; do
  469.         if which "$_cmd" > /dev/null 2>&1; then
  470.           _shortcmd=${_cmd##*/}
  471.           observe "running $_shortcmd in $_dir font directory"
  472.       _cmd_opts=
  473.           if [ "$_shortcmd" = "update-fonts-alias" ]; then
  474.             _cmd_opts=--x11r7-layout
  475.           fi
  476.           if [ "$_shortcmd" = "update-fonts-dir" ]; then
  477.             _cmd_opts=--x11r7-layout
  478.           fi
  479.           if [ "$_shortcmd" = "update-fonts-scale" ]; then
  480.             _cmd_opts=--x11r7-layout
  481.           fi
  482.           $_cmd $_cmd_opts $_dir || warn "$_cmd $_cmd_opts $_dir" \
  483.                               "failed; font directory data may not" \
  484.                               "be up to date"
  485.         else
  486.           warn "$_cmd not found; not updating corresponding $_dir font" \
  487.                "directory data"
  488.         fi
  489.       done
  490.     else
  491.       warn "$_dir is not a directory; not updating font directory data"
  492.     fi
  493.   done
  494. }
  495.  
  496. remove_conffile_prepare () {
  497.   # syntax: remove_conffile_prepare filename official_md5sum ...
  498.   #
  499.   # Check a conffile "filename" against a list of canonical MD5 checksums.
  500.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  501.   # operands provided, then prepare the conffile for removal from the system.
  502.   # We defer actual deletion until the package is configured so that we can
  503.   # roll this operation back if package installation fails.
  504.   #
  505.   # Call this function from a preinst script in the event $1 is "upgrade" or
  506.   # "install" and verify $2 to ensure the package is being upgraded from a
  507.   # version (or installed over a version removed-but-not-purged) prior to the
  508.   # one in which the conffile was obsoleted.
  509.  
  510.   #local conffile current_checksum
  511.  
  512.   # validate arguments
  513.   if [ $# -lt 2 ]; then
  514.     usage_error "remove_conffile_prepare() called with wrong number of" \
  515.                 "arguments; expected at least 2, got $#"
  516.     exit $SHELL_LIB_USAGE_ERROR
  517.   fi
  518.  
  519.   _conffile="$1"
  520.   shift
  521.  
  522.   # does the _conffile even exist?
  523.   if [ -e "$_conffile" ]; then
  524.     # calculate its checksum
  525.     _current_checksum=$(md5sum < "$_conffile" | sed 's/[[:space:]].*//')
  526.     # compare it to each supplied checksum
  527.     while [ -n "$1" ]; do
  528.       if [ "$_current_checksum" = "$1" ]; then
  529.         # we found a match; move the confffile and stop looking
  530.         observe "preparing obsolete conffile $_conffile for removal"
  531.         mv "$_conffile" "$_conffile.$THIS_PACKAGE-tmp"
  532.         break
  533.       fi
  534.       shift
  535.     done
  536.   fi
  537. }
  538.  
  539. remove_conffile_commit () {
  540.   # syntax: remove_conffile_commit filename
  541.   #
  542.   # Complete the removal of a conffile "filename" that has become obsolete.
  543.   #
  544.   # Call this function from a postinst script after having used
  545.   # remove_conffile_prepare() in the preinst.
  546.  
  547.   #local conffile
  548.  
  549.   # validate arguments
  550.   if [ $# -ne 1 ]; then
  551.     usage_error "remove_conffile_commit() called with wrong number of" \
  552.                 "arguments; expected 1, got $#"
  553.     exit $SHELL_LIB_USAGE_ERROR
  554.   fi
  555.  
  556.   _conffile="$1"
  557.  
  558.   # if the temporary file created by remove_conffile_prepare() exists, remove it
  559.   if [ -e "$_conffile.$THIS_PACKAGE-tmp" ]; then
  560.     observe "committing removal of obsolete conffile $_conffile"
  561.     rm "$_conffile.$THIS_PACKAGE-tmp"
  562.   fi
  563. }
  564.  
  565. remove_conffile_rollback () {
  566.   # syntax: remove_conffile_rollback filename
  567.   #
  568.   # Roll back the removal of a conffile "filename".
  569.   #
  570.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  571.   # or "abort-install" is  after having used remove_conffile_prepare() in the
  572.   # preinst.
  573.  
  574.   #local conffile
  575.  
  576.   # validate arguments
  577.   if [ $# -ne 1 ]; then
  578.     usage_error "remove_conffile_rollback() called with wrong number of" \
  579.                 "arguments; expected 1, got $#"
  580.     exit $SHELL_LIB_USAGE_ERROR
  581.   fi
  582.  
  583.   _conffile="$1"
  584.  
  585.   # if the temporary file created by remove_conffile_prepare() exists, move it
  586.   # back
  587.   if [ -e "$_conffile.$THIS_PACKAGE-tmp" ]; then
  588.     observe "rolling back removal of obsolete conffile $_conffile"
  589.     mv "$_conffile.$THIS_PACKAGE-tmp" "$_conffile"
  590.   fi
  591. }
  592.  
  593. replace_conffile_with_symlink_prepare () {
  594.   # syntax: replace_conffile_with_symlink_prepare oldfilename newfilename \
  595.   # official_md5sum ...
  596.   #
  597.   # Check a conffile "oldfilename" against a list of canonical MD5 checksums.
  598.   # If the file's current MD5 checksum matches one of the "official_md5sum"
  599.   # operands provided, then prepare the conffile for removal from the system.
  600.   # We defer actual deletion until the package is configured so that we can
  601.   # roll this operation back if package installation fails. Otherwise copy it
  602.   # to newfilename and let dpkg handle it through conffiles mechanism.
  603.   #
  604.   # Call this function from a preinst script in the event $1 is "upgrade" or
  605.   # "install" and verify $2 to ensure the package is being upgraded from a
  606.   # version (or installed over a version removed-but-not-purged) prior to the
  607.   # one in which the conffile was obsoleted.
  608.  
  609.   #local conffile current_checksum
  610.  
  611.   # validate arguments
  612.   if [ $# -lt 3 ]; then
  613.     usage_error "replace_conffile_with_symlink_prepare() called with wrong" \
  614.                 " number of arguments; expected at least 3, got $#"
  615.     exit $SHELL_LIB_USAGE_ERROR
  616.   fi
  617.  
  618.   _oldconffile="$1"
  619.   shift
  620.   _newconffile="$1"
  621.   shift
  622.  
  623.   remove_conffile_prepare "$_oldconffile" "$@"
  624.   # If $_oldconffile still exists, then md5sums didn't match.
  625.   # Copy it to new one.
  626.   if [ -f "$_oldconffile" ]; then
  627.     cp "$_oldconffile" "$_newconffile"
  628.   fi
  629.  
  630. }
  631.  
  632. replace_conffile_with_symlink_commit () {
  633.   # syntax: replace_conffile_with_symlink_commit oldfilename
  634.   #
  635.   # Complete the removal of a conffile "oldfilename" that has been
  636.   # replaced by a symlink.
  637.   #
  638.   # Call this function from a postinst script after having used
  639.   # replace_conffile_with_symlink_prepare() in the preinst.
  640.  
  641.   #local conffile
  642.  
  643.   # validate arguments
  644.   if [ $# -ne 1 ]; then
  645.     usage_error "replace_conffile_with_symlink_commit() called with wrong" \
  646.                 "number of arguments; expected 1, got $#"
  647.     exit $SHELL_LIB_USAGE_ERROR
  648.   fi
  649.  
  650.   _conffile="$1"
  651.  
  652.   remove_conffile_commit "$_conffile"
  653. }
  654.  
  655. replace_conffile_with_symlink_rollback () {
  656.   # syntax: replace_conffile_with_symlink_rollback oldfilename newfilename
  657.   #
  658.   # Roll back the replacing of a conffile "oldfilename" with symlink to
  659.   # "newfilename".
  660.   #
  661.   # Call this function from a postrm script in the event $1 is "abort-upgrade"
  662.   # or "abort-install" and verify $2 to ensure the package failed to upgrade
  663.   # from a version (or install over a version removed-but-not-purged) prior
  664.   # to the one in which the conffile was obsoleted.
  665.   # You should have  used replace_conffile_with_symlink_prepare() in the
  666.   # preinst.
  667.  
  668.   #local conffile
  669.  
  670.   # validate arguments
  671.   if [ $# -ne 2 ]; then
  672.     usage_error "replace_conffile_with_symlink_rollback() called with wrong" \
  673.                 "number of arguments; expected 2, got $#"
  674.     exit $SHELL_LIB_USAGE_ERROR
  675.   fi
  676.  
  677.   _oldconffile="$1"
  678.   _newconffile="$2"
  679.  
  680.   remove_conffile_rollback "$_oldconffile"
  681.   if [ -f "$_newconffile" ]; then
  682.     rm "$_newconffile"
  683.   fi
  684. }
  685.  
  686. run () {
  687.   # syntax: run command [ argument ... ]
  688.   #
  689.   # Run specified command with optional arguments and report its exit status.
  690.   # Useful for commands whose exit status may be nonzero, but still acceptable,
  691.   # or commands whose failure is not fatal to us.
  692.   #
  693.   # NOTE: Do *not* use this function with db_get or db_metaget commands; in
  694.   # those cases the return value of the debconf command *must* be checked
  695.   # before the string returned by debconf is used for anything.
  696.  
  697.   #local retval
  698.  
  699.   # validate arguments
  700.   if [ $# -lt 1 ]; then
  701.     usage_error "run() called with wrong number of arguments; expected at" \
  702.                 "least 1, got $#"
  703.     exit $SHELL_LIB_USAGE_ERROR
  704.   fi
  705.  
  706.   "$@" || _retval=$?
  707.  
  708.   if [ ${_retval:-0} -ne 0 ]; then
  709.     observe "command \"$*\" exited with status $_retval"
  710.   fi
  711. }
  712.  
  713. register_x_lib_dir_with_ld_so () {
  714.   # syntax: register_x_lib_dir_with_ld_so
  715.   #
  716.   # Configure the dynamic loader ld.so to search /usr/X11R6/lib for shared
  717.   # libraries.
  718.   #
  719.   # Call this function from the postinst script of a package that places a
  720.   # shared library in /usr/X11R6/lib, before invoking ldconfig.
  721.  
  722.   #local dir ldsoconf
  723.  
  724.   _dir="/usr/X11R6/lib"
  725.   _ldsoconf="/etc/ld.so.conf"
  726.  
  727.   # is the line not already present?
  728.   if ! fgrep -qsx "$_dir" "$_ldsoconf"; then
  729.     observe "adding $_dir directory to $_ldsoconf"
  730.     echo "$_dir" >> "$_ldsoconf"
  731.   fi
  732. }
  733.  
  734. deregister_x_lib_dir_with_ld_so () {
  735.   # syntax: deregister_x_lib_dir_with_ld_so
  736.   #
  737.   # Configure dynamic loader ld.so to not search /usr/X11R6/lib for shared
  738.   # libraries, if and only if no shared libaries remain there.
  739.   #
  740.   # Call this function from the postrm script of a package that places a shared
  741.   # library in /usr/X11R6/lib, in the event "$1" is "remove", and before
  742.   # invoking ldconfig.
  743.  
  744.   #local dir ldsoconf fgrep_status cmp_status
  745.  
  746.   _dir="/usr/X11R6/lib"
  747.   _ldsoconf="/etc/ld.so.conf"
  748.  
  749.   # is the line present?
  750.   if fgrep -qsx "$_dir" "$_ldsoconf"; then
  751.     # are there any shared objects in the directory?
  752.     if [ "$(echo "$_dir"/lib*.so.*.*)" = "$_dir/lib*.so.*.*" ]; then
  753.       # glob expansion produced nothing, so no shared libraries are present
  754.       observe "removing $_dir directory from $_ldsoconf"
  755.       # rewrite the file (very carefully)
  756.       set +e
  757.       fgrep -svx "$_dir" "$_ldsoconf" > "$_ldsoconf.dpkg-tmp"
  758.       _fgrep_status=$?
  759.       set -e
  760.       case $_fgrep_status in
  761.         0|1) ;; # we don't actually care if any lines matched or not
  762.         *) die "error reading \"$_ldsoconf\"; fgrep exited with status" \
  763.           "$_fgrep_status" ;;
  764.       esac
  765.       set +e
  766.       cmp -s "$_ldsoconf.dpkg-tmp" "$_ldsoconf"
  767.       _cmp_status=$?
  768.       set -e
  769.       case $_cmp_status in
  770.         0) rm "$_ldsoconf.dpkg-tmp" ;; # files are identical
  771.         1) mv "$_ldsoconf.dpkg-tmp" "$_ldsoconf" ;; # files differ
  772.         *) die "error comparing \"$_ldsoconf.dpkg-tmp\" to \"$_ldsoconf\";" \
  773.           "cmp exited with status $_cmp_status" ;;
  774.       esac
  775.     fi
  776.   fi
  777. }
  778.  
  779. make_symlink_sane () {
  780.   # syntax: make_symlink_sane symlink target
  781.   #
  782.   # Ensure that the symbolic link symlink exists, and points to target.
  783.   #
  784.   # If symlink does not exist, create it and point it at target.
  785.   #
  786.   # If symlink exists but is not a symbolic link, back it up.
  787.   #
  788.   # If symlink exists, is a symbolic link, but points to the wrong location, fix
  789.   # it.
  790.   #
  791.   # If symlink exists, is a symbolic link, and already points to target, do
  792.   # nothing.
  793.   #
  794.   # This function wouldn't be needed if ln had an -I, --idempotent option.
  795.  
  796.   # Validate arguments.
  797.   if [ $# -ne 2 ]; then
  798.     usage_error "make_symlink_sane() called with wrong number of arguments;" \
  799.       "expected 2, got $#"
  800.     exit $SHELL_LIB_USAGE_ERROR
  801.   fi
  802.  
  803.   # We could just use the positional parameters as-is, but that makes things
  804.   # harder to follow.
  805.   #local symlink target
  806.  
  807.   _symlink="$1"
  808.   _target="$2"
  809.  
  810.   if [ -L "$_symlink" ] && [ "$(readlink "$_symlink")" = "$_target" ]; then
  811.       observe "link from $_symlink to $_target already exists"
  812.   else
  813.     observe "creating symbolic link from $_symlink to $_target"
  814.     mkdir -p "${_target%/*}" "${_symlink%/*}"
  815.     ln -s -b -S ".dpkg-old" "$_target" "$_symlink"
  816.   fi
  817. }
  818.  
  819. migrate_dir_to_symlink () {
  820.   # syntax: migrate_dir_to_symlink old_location new_location
  821.   #
  822.   # Per Debian Policy section 6.5.4, "A directory will never be replaced by a
  823.   # symbolic link to a directory or vice versa; instead, the existing state
  824.   # (symlink or not) will be left alone and dpkg will follow the symlink if
  825.   # there is one."
  826.   #
  827.   # We have to do it ourselves.
  828.   #
  829.   # This function moves the contents of old_location, a directory, into
  830.   # new_location, a directory, then makes old_location a symbolic link to
  831.   # new_location.
  832.   #
  833.   # old_location need not exist, but if it does, it must be a directory (or a
  834.   # symlink to a directory).  If it is not, it is backed up.  If new_location
  835.   # exists already and is not a directory, it is backed up.
  836.   #
  837.   # This function should be called from a package's preinst so that other
  838.   # packages unpacked after this one --- but before this package's postinst runs
  839.   # --- are unpacked into new_location even if their payloads contain
  840.   # old_location filespecs.
  841.  
  842.   # Validate arguments.
  843.   if [ $# -ne 2 ]; then
  844.     usage_error "migrate_dir_to_symlink() called with wrong number of"
  845.                 "arguments; expected 2, got $#"
  846.     exit $SHELL_LIB_USAGE_ERROR
  847.   fi
  848.  
  849.   # We could just use the positional parameters as-is, but that makes things
  850.   # harder to follow.
  851.   local _new _old
  852.  
  853.   _old="$1"
  854.   _new="$2"
  855.  
  856.   # Is old location a symlink?
  857.   if [ -L "$_old" ]; then
  858.     # Does it already point to new location?
  859.     if [ "$(readlink "$_old")" = "$_new" ]; then
  860.       # Nothing to do; migration has already been done.
  861.       observe "migration of $_old to $_new already done"
  862.       return 0
  863.     else
  864.       # Back it up.
  865.       warn "backing up symbolic link $_old as $_old.dpkg-old"
  866.       mv -b "$_old" "$_old.dpkg-old"
  867.     fi
  868.   fi
  869.  
  870.   # Does old location exist, but is not a directory?
  871.   if [ -e "$_old" ] && ! [ -d "$_old" ]; then
  872.       # Back it up.
  873.       warn "backing up non-directory $_old as $_old.dpkg-old"
  874.       mv -b "$_old" "$_old.dpkg-old"
  875.   fi
  876.  
  877.   observe "migrating $_old to $_new"
  878.  
  879.   # Is new location a symlink?
  880.   if [ -L "$_new" ]; then
  881.     # Does it point the wrong way, i.e., back to where we're migrating from?
  882.     if [ "$(readlink "$_new")" = "$_old" ]; then
  883.       # Get rid of it.
  884.       observe "removing symbolic link $_new which points to $_old"
  885.       rm "$_new"
  886.     else
  887.       # Back it up.
  888.       warn "backing up symbolic link $_new as $_new.dpkg-old"
  889.       mv -b "$_new" "$_new.dpkg-old"
  890.     fi
  891.   fi
  892.  
  893.   # Does new location exist, but is not a directory?
  894.   if [ -e "$_new" ] && ! [ -d "$_new" ]; then
  895.     warn "backing up non-directory $_new as $_new.dpkg-old"
  896.     mv -b "$_new" "$_new.dpkg-old"
  897.   fi
  898.  
  899.   # Create new directory if it does not yet exist.
  900.   if ! [ -e "$_new" ]; then
  901.     observe "creating $_new"
  902.     mkdir -p "$_new"
  903.   fi
  904.  
  905.   # Copy files in old location to new location.  Back up any filenames that
  906.   # already exist in the new location with the extension ".dpkg-old".
  907.   observe "copying files from $_old to $_new"
  908.   if ! (cd "$_old" && cp -a -b -S ".dpkg-old" . "$_new"); then
  909.     die "error(s) encountered while copying files from $_old to $_new"
  910.   fi
  911.  
  912.   # Remove files at old location.
  913.   observe "removing $_old"
  914.   rm -r "$_old"
  915.  
  916.   # Create symlink from old location to new location.
  917.   make_symlink_sane "$_old" "$_new"
  918. }
  919.  
  920. # vim:set ai et sw=2 ts=2 tw=80:
  921.  
  922. # GOBSTOPPER: The X Strike Force shell library ends here.
  923.  
  924. if [ "$1" = "remove" ] || [ "$1" = "deconfigure" ]; then
  925.   # deregister available X cursor themes with update-alternatives
  926.   update-alternatives --remove x-cursor-theme /etc/X11/cursors/core.theme
  927.   for THEME in whiteglass redglass handhelds; do
  928.     update-alternatives --remove x-cursor-theme "/etc/X11/cursors/$THEME.theme"
  929.   done
  930. fi
  931.  
  932.  
  933.  
  934. exit 0
  935.  
  936. # vim:set ai et sts=2 sw=2 tw=0:
  937.